﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学任务安排 - 计划任务合班");
		
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		/*sql = "SELECT 
					COUNT(DISTINCT t_course.cid) countCid, 
					t_institute.institute_id, 
					t_institute.institute_name, 
					SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) sumCidx  
				FROM 
					t_plan 
					INNER JOIN t_course ON t_course.cid = t_plan.cid 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_plan.term_id = :termId 
					AND 
					(t_plan.cidx > 'XXX' OR t_plan.cidx < 'XXX') 
				GROUP BY 
					t_institute.institute_id, t_institute.institute_name 
				ORDER BY 
					t_institute.institute_name ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		rs_ins = queryObj.execute( sql=sql ).getResult(); */
		
		currentTab = event.getArg("TabID", "labDepartment");
		
		depId = event.getArg("DepID");
		
		rs_course = queryNew("cid");
		rs_courseDone = queryNew("cid");
		rs_departmentEntity = queryNew("institute_name");
		
		Keyword = event.getArg("Keywords");
		
	    
	    currentTab = "labCourse";
	    
	    sql = "SELECT institute_name FROM t_institute WHERE institute_id = :instituteId ";
	    
	    queryObj = new query( datasource=application.dnsSlave );
	    queryObj.addParam( name="instituteId", value=depId, cfsqltype="cf_sql_varchar" );
	    rs_departmentEntity = queryObj.execute( sql=sql ).getResult(); 
    
	    sql = "SELECT 
				    t_course.cid, 
				    t_course.course_name, 
				    t_course.course_credit, 
				    t_course.period_week, 
				    t_course.period, 
				    t_course.period_theory, 
				    t_course.period_practice,
				    t_course.course_code,
				    t_course.prop_id   
			    FROM 
				    t_course 
			    WHERE 
				    abandon = '0' 
				    and 
				    t_course.period_week != '0'
			    ORDER BY 
				    t_course.course_name ";
				    
	    queryObj = new query( datasource=application.dnsSlave );
	    
	    rs_course = queryObj.execute( sql=sql ).getResult(); 
				    
	    if ( len(Keyword) ) {
		    
		    sql = "SELECT 
				    t_course.cid, 
				    t_course.course_name, 
				    t_course.course_credit, 
				    t_course.period_week, 
				    t_course.period, 
				    t_course.period_theory, 
				    t_course.period_practice,
				    t_course.course_code,
				    t_course.prop_id  
			    FROM 
				    t_course 
			    WHERE 
				    abandon = '0' 
				    and (
					    t_course.course_name LIKE :condition 
					    OR
					    t_course.course_code LIKE :condition 
				    )
				    and 
				    t_course.period_week != '0'
			    ORDER BY 
				    t_course.course_name ";
				    
		    queryObj = new query( datasource=application.dnsSlave );
		    
		    queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
	    
		    rs_course = queryObj.execute( sql=sql ).getResult(); 
	    }
	    
    
	    sql = "SELECT 
				    t_course.cid, 
				    t_course.course_name, 
				    t_course.course_credit, 
				    t_course.period_week, 
				    t_course.period, 
				    t_course.period_theory, 
				    t_course.period_practice, 
				    SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) SumCidx, 
				    COUNT(*) count, 
				    t_course.course_code 
			    FROM 
				    t_plan 
				    INNER JOIN t_course ON t_course.cid = t_plan.cid 
			    WHERE 
				    t_plan.term_id = :termId 
				    AND 
				    (t_plan.cidx > 'XXX' OR t_plan.cidx < 'XXX') 
				    AND 
				    t_course.institute_id = :depID 
			    GROUP BY 
				    t_course.cid, 
				    t_course.course_name, 
				    t_course.course_credit, 
				    t_course.period_week, 
				    t_course.period, 
				    t_course.period_theory, 
				    t_course.period_practice, 
				    t_course.course_code 
			    HAVING 
				    SUM(CASE WHEN t_plan.cidx = '000' THEN 1 ELSE 0 END) = 0 
			    ORDER BY 
				    t_course.course_name ";
	    queryObj = new query( datasource=application.dnsSlave );
	    queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
	    queryObj.addParam( name="depID", value=depId, cfsqltype="cf_sql_varchar" );
	    rs_courseDone = queryObj.execute( sql=sql ).getResult(); 
				    
	    if ( rs_course.recordCount eq 0 and rs_courseDone.recordCount gt 0 ) {
		    currentTab = event.getArg("TabID", "labDone");
	    }
	    
		
		passArgs = structNew();
		structInsert( passArgs, "TID", termId, true);
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<cfif len(depId)>
					<a class="uiButton" href="<cfoutput>#buildURL('classMerge')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">计划任务合班</span></a>
					<cfelse>
					<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务安排</span></a>
				</cfif>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput>计划任务合班
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						
							<!---<cfif rs_course.recordCount>--->
								<span <cfif currentTab eq "labCourse">class="active"</cfif> id="labCourse" tabTarget="Course">需合班课程</span>
							<!---</cfif>--->
							<cfif rs_courseDone.recordCount>
								<span <cfif currentTab eq "labDone">class="active"</cfif> id="labDone" tabTarget="Done">已合班课程</span>
							</cfif>
						
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<!---<div id="Department" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton" href="<cfoutput>#buildURL('allTaskUnlockDo', passArgs)#</cfoutput>"><i class="mrs img btnExecute"></i><span class="uiButtonText">解锁计划任务</span></a>
						</div>
						<h3>任课单位</h3>
						<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务共计 <em><cfoutput>1</cfoutput></em> 个任课单位共同完成.</p>
						<hr/>
					</div>
					
					<div class="clearfix">
						<div class="UICardTable">
                            <cfloop query="rs_ins">
								<cfset structInsert(passArgs, "DepID", rs_ins.institute_id, true) />
								<dl>
									<dt>
										<a href="<cfoutput>#buildURL('classMerge', passArgs)#</cfoutput>">
										<em class="collection"><!--imgholder--></em>
										<dd>
											<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
											<div><cfoutput>#rs_ins.countCid#</cfoutput> 门课程<cfif rs_ins.sumCidx gt 0>, <cfoutput>#rs_ins.sumCidx#</cfoutput> 班待处理</cfif></div>
										</dd>
										</a>
									</dt>
								</dl>
							</cfloop>
						</div>
					</div>
					
				</div>--->
				
				<!---<cfif rs_course.recordCount>--->

					<div id="Course" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
						
							<cfset passArgs = structNew() />
							<cfset structInsert( passArgs, "DepID", depId, true) />
							<cfset structInsert( passArgs, "TID", termId, true) />
                                   
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programPlanDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学计划</span></a>
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programTaskDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学任务</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务需承担 <em><cfoutput>#rs_course.recordCount#</cfoutput></em> 门课程.</p>
								<hr/>
							</div>
						
						</cfif>
                              
                              <form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('classMerge',passArgs)#</cfoutput>">
                                   <input type="hidden" name="TabID" value="labSearch" />
                                   
                                   <div class="label">
                                        <b>课程名或者课程号</b>
                                        <input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
                                   </div>
                                 
                                   <div class="lable">
                                        <input class="button1" type="submit" value="搜索" />
                                   </div>
                                     <hr/>
                              </form>
					
					
						<cfset structDelete(passArgs, "DepID", false) />
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>课程</td>
									<td width="100">课程号</td>
									<td width="25">学分</td>
                                             <td width="45" align="center">类型</td>
									<td width="70">排课周学时</td>
									<td width="40">总学时</td>
									<td width="50">理论学时</td>
									<td width="50">实践学时</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_course">
									<cfset row++ />
									<cfset structInsert(passArgs, "CID", rs_course.cid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_course.cid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_course.course_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_course.course_code#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_course.course_credit, '_.__')#</cfoutput></span></td>
                                                  <td align="center"><cfif rs_course.prop_id eq '1'>必修<cfelse>选修</cfif></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_practice#</cfoutput></span></td>
										<cfif rs_course.course_name eq '实习' OR rs_course.course_name EQ '学士学位论文'>
                                                  		<td><a href="<cfoutput>#buildURL('classMergeByCourseSpecial', passArgs)#</cfoutput>" class="stat struct"></a></td>
                                                  	<cfelse>
                                                       	<td><a href="<cfoutput>#buildURL('classMergeByCourse', passArgs)#</cfoutput>" class="stat struct"></a></td>
                                                  </cfif>
										
									</tr>
								</cfloop>
							</tbody>
						</table>
	
					</div>
					
				<!---</cfif>--->
				
				<cfif rs_courseDone.recordCount>

					<div id="Done" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
						
							<cfset passArgs = structNew() />
							<cfset structInsert( passArgs, "DepID", depId, true) />
							<cfset structInsert( passArgs, "TID", termId, true) />
						
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programPlanDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学计划</span></a>
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('programTaskDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载教学任务</span></a>
								</div>
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p><span class="img icon16x16 message"></span><em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期教学任务需承担 <em><cfoutput>#rs_course.recordCount#</cfoutput></em> 门课程.</p>
								<hr/>
							</div>
						
						</cfif>
					
					
						<cfset structDelete(passArgs, "DepID", false) />
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>课程</td>
									<td width="100">课程号</td>
									<td width="25">学分</td>
									<td width="70">排课周学时</td>
									<td width="40">总学时</td>
									<td width="50">理论学时</td>
									<td width="50">实践学时</td>
									<td width="80">任务安排进度</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_courseDone">
									<cfset row++ />
									<cfset structInsert(passArgs, "CID", rs_courseDone.cid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_courseDone.cid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_courseDone.course_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_courseDone.course_code#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_courseDone.course_credit, '_.__')#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_courseDone.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#(rs_courseDone.count-rs_courseDone.SumCidx)# / #rs_courseDone.count#</cfoutput></span></td>
										<td><a href="<cfoutput>#buildURL('classMergeByCourse', passArgs)#</cfoutput>" class="stat config"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
	
					</div>
					
				</cfif>
				
			</div>
		</li>
	</ul>
</div>




